package com.levy.utils.jvisualVM;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by levy on 2018/5/28.
 */
public class MyThread extends Thread {

    private static List<String> list = new ArrayList<>();

    public static void main(String[] args) {
        for (int i = 0; i < 100000; i++) {
            list.add(String.valueOf(i));
        }

        MyThread mt1 = new MyThread("Thread a");
        MyThread mt2 = new MyThread("Thread b");
        MyThread mt3 = new MyThread("Thread c");
        MyThread mt4 = new MyThread("Thread d");

        mt1.setName("My-Thread-1 ");
        mt2.setName("My-Thread-2 ");
        mt3.setName("My-Thread-3 ");
        mt4.setName("My-Thread-4 ");

        mt1.start();
        mt2.start();
        mt3.start();
        mt4.start();
    }

    public MyThread(String name) {


    }

    @Override
    public void run() {
        for (String s : list) {
            synchronized (this) {
//                while (true) {
                System.out.println(this.getName());
                System.out.println(s);
//                }
            }
        }


    }
}
